package edu.rit.varapp.utilities;

import edu.rit.varapp.db.DatabaseConnection;
import edu.rit.varapp.logging.Logging;
import java.sql.SQLException;

/**
 * Attempts to sever the database connection during a shutdown sequence in the JVM. Also removes any lock on the log
 * files. This should be added as a shutdown hook in the entry point to the application.
 * @author Eric Kisner
 */
public class CleanupThread extends Thread {

    @Override
    public void run() {
        try {
            DatabaseConnection.instance().close();
        } catch( SQLException sqle ) {
            Logging.log( "There was an error trying to close the connection to the database: " + sqle.getMessage(),
                         DatabaseConnection.class );
        }
        Logging.close();
    }
}
